﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="paringesindus_v3_vastus", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(ParingesindusV3Vastus))]
    public class ParingesindusV3VastusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IParingesindusV3Vastus clazz;
        
        public ParingesindusV3VastusSerializer(IParingesindusV3Vastus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ettevotjad");
            if (clazz.Ettevotjad!=null) {
                global::Xtee.Core.SerializationMetadata metaEttevotjad = this.GetMetaData(clazz.Ettevotjad);
                Writer.WriteTypeAttribute(metaEttevotjad.TypeQualifiedName.Namespace, metaEttevotjad.TypeQualifiedName.Name);
                metaEttevotjad.NewSerializer(clazz.Ettevotjad).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Ettevotjad");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ettevotjad") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>paringesindus_v3_vastus>ettevotjad");
                }
                global::Xtee.Core.SerializationMetadata metaEttevotjad = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusV3Ettevotted>(Reader, "paringesindus_v3_ettevotted", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Ettevotjad = metaEttevotjad.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IParingesindusV3Ettevotted>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ettevotjad");
                    metaEttevotjad.NewSerializer(clazz.Ettevotjad).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>paringesindus_v3_vastus>ettevotjad", Reader.LocalName);
            }
        }
    }
}
